package lotteryProgram;

import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class LotteryProgram {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Set<String> prizes = generatePrizes();
        Random random = new Random();

        System.out.println("请输入一个正整数进行抽奖，输入0退出程序。");
        int count=1;
        while (!prizes.isEmpty()) {
            System.out.print("抽奖第"+(count++)+"次: ");
            int input = scanner.nextInt();

            if (input == 0) {
                System.out.println("程序已退出。");
                break;
            }

            if (input <= 0) {
                System.out.println("请输入一个正整数。");
                continue;
            }

            // 模拟抽奖
            String prize = prizes.toArray(new String[0])[random.nextInt(prizes.size())];
            System.out.println("恭喜你抽中了: " + prize);
            prizes.remove(prize);
        }

        scanner.close();
    }

    private static Set<String> generatePrizes() {
        Set<String> prizes = new HashSet<>();
        Random random = new Random();
        char[] letters = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        StringBuilder prizeBuilder;

        while (prizes.size() < 1000) {
            prizeBuilder = new StringBuilder();
            for (int i = 0; i < 10; i++) {
                int index = random.nextInt(letters.length);
                prizeBuilder.append(letters[index]);
            }
            String prize = prizeBuilder.toString();
            prizes.add(prize);
        }

        return prizes;
    }
}
